<div id="viewer-container"></div>
<script>
  CTS.ready(() => {
    let gui = new dat.GUI()
    let viewer = new CTS.Viewer('viewer-container', { sky: false, light: false }) //初始化场景
    viewer.camera.position.set(40, 40, 40) //设置相机位置
    // 添加环境光
    viewer.scene.add(new CTS.AmbientLight(0x404040, 50))
    let floors = new CTS.Floors(viewer)
    let option = {
      map: '/resources/material/polished_concrete_basecolor.jpg',
      normalMap: '/resources/material/polished_concrete_normal.jpg',
      reflectivity: 0.49,
      mirror: 0.25,
      mixStrength: 26,
      color: '#ffffff'
    }
    gui.add(option, 'reflectivity').name('反射度').onChange(update)
    gui.add(option, 'mirror').name('镜面度').onChange(update)
    gui.add(option, 'mixStrength').name('混合度').onChange(update)
    gui.addColor(option, 'color').name('模型颜色').onChange(update)
    let ImgReflector = floors.createImgReflector(option)

    let model
    new CTS.ModelLoder(viewer).loadModelToScene('resources/model/robot1.gltf', _model => {
      model = _model
      model.startAnima()
      model.setScalc(0.2)

      function anima(i) {
        model.stopAnima() //开始动画之前先关闭之前播放的动画
        model.animaPlay(i, () => {
          anima(i)
        })
      }

      anima(0)
    })

    function update() {
      if (option.reflectivity) {
        ImgReflector.setReflectivity(option.reflectivity)
      }
      if (option.mirror) {
        ImgReflector.setMirror(option.mirror)
      }
      if (option.mixStrength) {
        ImgReflector.setMixStrength(option.mixStrength)
      }
      if (option.color) {
        ImgReflector.setColor(option.color)
      }
    }
  })
</script>
